<?php
// 项目测试-不继承 Controller类
use \Hyang\Model;
class emmaController{
    public function indexAction()
    {
        echo '---';
        // 回调与匿名函数
        $this->fback(function($obj){
            debug($obj,true);
        });
        $this->fback("8888888888");
        echo '<br>';
        debug([
            ceil(1.000),
            ceil(9.001),
        ],true);
    }
    public function fback($func=null)
    {
        // 回调测试
        if(is_callable($func)) $func($this);
        else{
            echo '$func不是一个函数变量<br>传入参数如下：';
            debug($func,true);
        }
    }
    public function modelAction()
    {
        // orcale 测试
        debug(function(&$data){
            return;//开关
            $oci = new Emma();
            $data = [
                '标题：Oracle数据库选项测试'
                //,$oci->build()->create()
                ///,$oci->build(true)->create()? 'Y':'N'
                //,$oci->create()? 'Y':'N'
                //,$oci->build(true)->drop()
                //,uniqid()
                //,$oci->data(['name'=>'Emma','remark'=>'数据测试，运行函数：“$oci->data([name=>Emma,remark=>数据测试，运行函数：“”])->add()”'])->build(true)->add()
                //,$oci->delete(['id'=>'123456']),$oci->_sql()
                //,$oci->add(['id'=>'123456','name'=>'手动数据','remark'=>'构造数据']),$oci->_sql()
                //,$oci->db->query('insert into "emma"("mtime","id","name","remark") values(\'2016-10-19 11:32:49\',\'123456\',\'手动数据\',\'构造数据\')')
                //,$oci->where(['id'=>'201610191140345806eb32e0b89'])->data(['name'=>'Join Cena'])->update(),$oci->_sql()
                //,$oci->delete(['id'=>'201610191140375806eb352f749']),$oci->_sql(),$oci->_error()
                //,$oci->select()//,$oci->_sql() 
                //,$oci->delete(),$oci->_sql() 
                //,$oci->drop(),$oci->error()
                //,$oci->dbInfo()->table(),$oci->_error()
                //,$oci->getOpt()
                ,$oci->dbInfo()->count()

            ];
        });
        // mysql 测试
        debug(function(&$data){
            return;//开关
            $opt = [
                'type'=>'mysql',
                'dbname'=>'cro',
                'user' => 'root',
                'password' => '151001',
            ];
            $ms = new Emma($opt);
            $data = [
                'mysql 数据库连接测试-//增删改查'
                //,$ms->table('project_list')->select()
                //,$ms->build(true)->create(),$ms->_error()
                //,$ms->data(['name'=>'Emma','remark'=>'数据测试，运行函数：“$oci->data([name=>Emma,remark=>数据测试，运行函数：“”])->add()”;其他MYSQL数据测试'])->add(),$ms->_sql()
                //,$ms->where(['id'=>'20161019155938580727eab2193'])->update(['id'=>'1314521','name'=>'Joshua Coenro','remark'=>'Joshua danm love you fat girl!']),$ms->_sql()
                //,$ms->where(['id'=>'20161019155940580727eca19a5'])->delete(),$ms->_sql(),$ms->_error()
                //,$ms->delete(['id'=>'20161019155940580727eca19a5']),$ms->_sql(),$ms->_error()
                //,$ms->select()
                //,$ms->delete(),$ms->_error()
                //,$ms->drop()
                //,$ms->getOpt()
                //,$ms->dbInfo()->table()
                //,$ms->dbInfo()->count()
                //,$ms->dbInfo()->database()
                //,$ms->dbInfo()->view()
                //,$ms->db->_error()
                //,$ms->db->query('select * from `project_list`')
            ];
            //debug($ms->db,true);
            //debug($ms->db->db,true);
        });

        // mysql 测试
        debug(function(&$data){
            //return;//开关
            $opt = [
                'type'=>'mysql',
                'dbname'=>'cro2',
                'user' => 'jc',
                'password' => '123456'
            ];
            $db = new Model($opt);
            $data = [
                'cro2-mysql-数据测试'
                ,$db->table('sys_visitor')->select()
            ];
        });
    }
    public function infoAction()
    {
        phpinfo();
    }
    public function pgSQLAction()
    {
        debug(function(&$data){
            //return;// 调试器开关
            $opt = [
                'type'      => 'pgsql'
                ,'dbname'   => 'pgmr'
                ,'user'     => 'yang'
                ,'password' => '_conero'
            ];
            $m = new Emma($opt);
            //debug($m->_error(),true);
            $data = [
                'pgSQL 数据库PDO测试'
                //,$m->create(),$m->_error()
                //,$m->data(['name'=>'卜汝雪','remark'=>'我想在这世界上只有一个女人叫这个名字吧，其实只是胡话而已'])->add()
                ,$m->select()
                //,$m->where(['id'=>'20161024103552580d738855b72'])->data(['remark'=>'你在美国吗？在的话干嘛不让我知道呢，我到让不在那边，我在中国'])->update()
                ,$m->get('20161024104931580d76bb6d3b0')
                ,$m->where(['id'=>'20161024104931580d76bb6d3b0'])->delete()
                //,$m->table('brximl')->select(),$m->_sql()
                //,$m->query('select * from "brixml"')
                //,$m->db->query('select * from "brixml"'),$m->_error()
                //,$m->db->fetchRow('select * from brximl'),$m->_error()
                //,$m->db->query('select * from brximl'),$m->_error()                
            ];
            //debug($m->db,true);
            //debug($m->db->db,true);
        });
    }
    // 测试 MySQL PDO对象返回ID
    public function brximlAction()
    {
        // mysql://zhangyin:123456@127.0.0.1:3306/zaueen#utf8
        $opt = [
            'type'      => 'mysql'
            ,'dbname'   => 'zaueen'
            ,'user'     => 'zhangyin'
            ,'password' => '123456'
        ];
        $m = new Model($opt);
        /*        
        echo $m->table('tp5')->add(['remark'=>'85858']);
        // 返回当前该条数据的ID
        echo $m->db->db->lastInsertId();
        echo $m->getId();
        */
        echo $m->table('tp501')->add(['remark'=>'85858']);
        echo '<br>';
        echo $m->getId();
    }
}